home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / gs_pfile.ps < prev    next >
Text File  |  1996-01-10  |  6KB  |  180 lines

  1. %    Copyright (C) 1994, 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % Runtime support for minimum-space fonts and packed files.
  16.  
  17. % ****** NOTE: This file must be kept consistent with
  18. % ****** packfile.ps and wrfont.ps.
  19.  
  20. % ---------------- Packed file support ---------------- %
  21.  
  22. % A packed file is the concatenation of several file groups, each of which
  23. % is the result of compressing several files concatenated together.
  24. % The packed file begins with a procedure that creates an appropriate
  25. % decoding filter for each file group, as follows:
  26. %    <group-subfile-filter> -proc- <group-decode-filter>
  27. % Thus, accessing an individual file requires 4 parameters:
  28. % the starting address and length of the outer compressed file,
  29. % and the starting address and length of the inner file.
  30. /.packedfilefilter    % <file> <ostart> <olength> <istart> <ilength>
  31.             %   .packedfilefilter <filter>
  32.  { 4 index systemdict begin token pop end 6 1 roll
  33.     % Stack: fproc file ostart olength istart ilength
  34.    4 index 5 -1 roll setfileposition
  35.     % Stack: fproc file olength istart ilength
  36.    4 -2 roll () /SubFileDecode filter
  37.     % Stack: fproc istart ilength ofilter
  38.    4 -1 roll exec
  39.     % Filters don't support setfileposition, so we must skip data
  40.     % by reading it into a buffer.  We rely on the fact that
  41.     % save/restore don't affect file positions.
  42.     % Stack: istart ilength dfilter
  43.    save exch 1000 string
  44.     % Stack: istart ilength save dfilter scratch
  45.    4 index 1 index length idiv { 2 copy readstring pop pop } repeat
  46.    2 copy 0 8 -1 roll 2 index length mod getinterval readstring pop pop pop
  47.     % Stack: ilength save dfilter
  48.    exch restore exch () /SubFileDecode filter
  49.  } bind def
  50.  
  51. % Run a packed library file.
  52. /.runpackedlibfile    % <filename> <ostart> <olength> <istart> <ilength>
  53.             %   .runpackedlibfile
  54.  { 5 -1 roll findlibfile
  55.     { exch pop dup 6 2 roll .packedfilefilter
  56.       currentobjectformat exch 1 setobjectformat run
  57.       setobjectformat closefile
  58.     }
  59.     { 5 1 roll /findlibfile load /undefinedfilename signalerror
  60.     }
  61.    ifelse
  62.  } bind def
  63.  
  64. % ---------------- Compacted font support ---------------- %
  65.  
  66. % Compacted fonts written by wrfont.ps depend on the existence and
  67. % specifications of the procedures and data in this section.
  68.  
  69. /.compactfontdefault mark
  70.     /PaintType 0
  71.     /FontMatrix [0.001 0 0 0.001 0 0] readonly
  72.     /FontType 1
  73.     /Encoding StandardEncoding
  74. .dicttomark readonly def
  75.  
  76. /.checkexistingfont    % <fontname> <uid> <privatesize> <fontsize>
  77.             %   .checkexistingfont
  78.             %   {} (<font> on d-stack)
  79.             % <fontname> <uid> <privatesize> <fontsize>
  80.             %   .checkexistingfont
  81.             %   -save- --restore-- (<font> on d-stack)
  82.  { FontDirectory 4 index .knownget
  83.     { dup /UniqueID .knownget
  84.        { 4 index eq exch /FontType get 1 eq and }
  85.        { pop false }
  86.       ifelse
  87.     }
  88.     { false
  89.     }
  90.    ifelse
  91.     { save /restore load 6 2 roll }
  92.     { {} 5 1 roll }
  93.    ifelse
  94.    dict //.compactfontdefault exch copy begin
  95.    dict /Private exch def
  96.    Private begin
  97.      /MinFeature {16 16} def
  98.      /Password 5839 def
  99.      /UniqueID 1 index def
  100.    end
  101.    /UniqueID exch def
  102.    /FontName exch def
  103.  } bind def
  104.  
  105. /.knownEncodings [
  106.    ISOLatin1Encoding
  107.    StandardEncoding
  108.    SymbolEncoding
  109. ] readonly def
  110.  
  111. /.readCharStrings    % <count> <encrypt> .readCharStrings <dict>
  112.  { exch dup dict dup 3 -1 roll
  113.     { currentfile token pop dup type /integertype eq
  114.        { dup -8 bitshift //.knownEncodings exch get exch 255 and get } if
  115.       currentfile token pop dup type /nametype eq
  116.        { 2 index exch get
  117.        }
  118.        {    % Stack: encrypt dict dict key value
  119.      4 index { 4330 exch dup .type1encrypt exch pop } if
  120.      readonly
  121.        }
  122.       ifelse put dup
  123.     }
  124.    repeat pop exch pop
  125.  } bind def
  126.  
  127. % ---------------- Synthetic font support ---------------- %
  128.  
  129. % Create a new font by modifying an existing one.  paramdict contains
  130. % entries with the same keys as the ones found in a Type 1 font;
  131. % it should also contain enough empty entries to allow adding the
  132. % corresponding non-overridden entries from the original font dictionary,
  133. % including FID.  If paramdict includes a FontInfo entry, this will
  134. % also override the original font's FontInfo, entry by entry;
  135. % again, it must contain enough empty entries.
  136.  
  137. % Note that this procedure does not perform a definefont.
  138.  
  139. /.makemodifiedfont    % <fontdict> <paramdict> .makemodifiedfont <fontdict'>
  140.  { exch
  141.     {            % Stack: destdict key value
  142.       1 index /FID ne
  143.        { 2 index 2 index known
  144.       {        % Skip fontdict entry supplied in paramdict, but
  145.             % handle FontInfo specially.
  146.         1 index /FontInfo eq
  147.          { 2 index 2 index get        % new FontInfo
  148.            1 index                % old FontInfo
  149.         {    % Stack: destdict key value destinfo key value
  150.           2 index 2 index known
  151.            { pop pop }
  152.            { 2 index 3 1 roll put }
  153.           ifelse
  154.         }
  155.            forall pop
  156.          }
  157.         if
  158.       }
  159.       {        % No override, copy the fontdict entry.
  160.         2 index 3 1 roll put
  161.         dup dup    % to match pop pop below
  162.       }
  163.      ifelse
  164.        }
  165.       if
  166.       pop pop
  167.     } forall
  168.  } bind def
  169.  
  170. % Make a modified font and define it.  Note that unlike definefont,
  171. % this does not leave the font on the operand stack.
  172.  
  173. /.definemodifiedfont    % <fontdict> <paramdict> .definemodifiedfont -
  174.  { .makemodifiedfont
  175.    dup /FontName get exch definefont pop
  176.  } bind def
  177.